var mongoose=require('mongoose');
var User=mongoose.model('User',{
    name:String,
    number:Number,
    winner:Boolean,
    array:Array
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


User.update({name:'A'},{number:1101,winner:true,array:[1,2,3]},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    User.update({name:'B'},{number:1201,winner:false,array:[1,2]},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        User.update({name:'C'},{number:1301,winner:true,array:[1]},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            User.update({name:'D'},{number:1401,winner:false,array:[1,4]},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                User.update({name:'E'},{number:1501,winner:false,array:[3,2,1]},{upsert:true},(e,r)=>{
                    if(e)throw e;
                    console.log('Update:\n',r);

                    User.find((e,r)=>{
                        if(e)throw e;
                        console.log('\nFind All:\n',r);

                        User.find({
                            array:{
                                $size:3
                            }
                        },{number:true,array:true},(e,r)=>{
                            if(e)throw e;
                            console.log('\n====Find 4:\n',r);
                            process.exit(1);
                        });

                    });


                });


            });

        });

    });

});

/*
* {field:{$size:length}}
* 匹配field长度等于length
*
* $size不能于$gt,$lt等组合使用
* */